from django.db import models

# Create your models here.
from users.models import User
from vne_erp.utils.base_model import BaseModel


class Purchase(BaseModel):
    """采购模型类"""

    PURCHASE_ORDER_STATUS = (
        (1, "待到货"),
        (2, "已完成"),
        (3, "已取消"),
        (4, "待入库"),
        (5, "已入库"),
    )

    staff = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='采购人')
    order_id = models.CharField(max_length=38, verbose_name='采购订单号')
    sku_id = models.CharField(max_length=38, verbose_name='SKU_ID')
    email = models.CharField(max_length=50, verbose_name='采购人员email')
    # email = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='采购人员email')
    asin = models.CharField(max_length=38, verbose_name='ASIN')
    image_url = models.ImageField(upload_to='purchase_images', verbose_name='图片地址')
    color_size = models.CharField(max_length=20, verbose_name='颜色码数')
    chinese_node = models.CharField(max_length=30, verbose_name='中文报关')
    sell_price = models.DecimalField(max_digits=10, default=0, decimal_places=2, verbose_name='售价')
    pick_price = models.DecimalField(max_digits=10, default=0, decimal_places=2, verbose_name='调货价')
    road_price = models.DecimalField(max_digits=10, default=0, decimal_places=2, verbose_name='运费')
    weight = models.IntegerField(default=0, verbose_name='重量')
    numbers = models.IntegerField(default=0, verbose_name='数量')
    abroad_price = models.DecimalField(max_digits=10, default=0, decimal_places=2, verbose_name='境外运费')
    principal = models.DecimalField(max_digits=10, default=0, decimal_places=2, verbose_name='本金')
    profit = models.DecimalField(max_digits=10, default=0, decimal_places=2, verbose_name='利润')
    pick_goods_url = models.CharField(max_length=200, verbose_name='调货连接')
    status = models.SmallIntegerField(choices=PURCHASE_ORDER_STATUS, default=1, verbose_name="采购单状态")

    class Meta:
        db_table = 'tb_purchase'
        verbose_name = '采购管理'
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s:%s" % (self.id, self.email)

